import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../controllers/reset_pwd_controller.dart';

class ResetPwdView extends GetView<ResetPwdController> {
  const ResetPwdView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFEDF3FA),

      appBar: AppBar(
        title: Text(
          '重新设置密码',
          style: TextStyle(
            fontSize: 32.sp,
            fontFamily: 'Source Han Sans CN',
            color: const Color(0xFF333333),
          ),
        ),
        backgroundColor: const Color(0xFFEDF3FA),
        elevation: 0,
        centerTitle: true,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back_ios,
            color: const Color(0xFF333333),
            size: 40.sp,
          ),
          onPressed: () => Get.back(),
        ),
      ),
      body: _ResetPasswordForm(),
    );
  }
}

class _ResetPasswordForm extends StatefulWidget {
  @override
  _ResetPasswordFormState createState() => _ResetPasswordFormState();
}

class _ResetPasswordFormState extends State<_ResetPasswordForm> {
  bool _isNewPasswordVisible = false;
  bool _isConfirmPasswordVisible = false;
  final TextEditingController _newPasswordController = TextEditingController();
  final TextEditingController _confirmPasswordController =
      TextEditingController();

  @override
  void dispose() {
    _newPasswordController.dispose();
    _confirmPasswordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 30.w),
      child: Column(
        children: [
          SizedBox(height: 100.h),
          // 新密码输入框
          Container(
            width: 690.w,
            height: 110.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.r),
            ),
            child: Row(
              children: [
                SizedBox(width: 30.w),
                Text(
                  '新密码',
                  style: TextStyle(
                    fontSize: 28.sp,
                    fontFamily: 'Source Han Sans',
                    color: const Color(0xFF333333),
                    height: 1.0,
                  ),
                ),
                SizedBox(width: 60.w),
                Expanded(
                  child: TextField(
                    controller: _newPasswordController,
                    obscureText: !_isNewPasswordVisible,
                    decoration: InputDecoration(
                      hintText: '请输入新密码',
                      hintStyle: TextStyle(
                        fontSize: 28.sp,
                        fontFamily: 'Source Han Sans CN',
                        color: const Color(0xFF999999),
                        height: 1.0,
                      ),
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.zero,
                    ),
                    style: TextStyle(
                      fontSize: 28.sp,
                      fontFamily: 'Source Han Sans CN',
                      color: const Color(0xFF333333),
                    ),
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    setState(() {
                      _isNewPasswordVisible = !_isNewPasswordVisible;
                    });
                  },
                  child: Padding(
                    padding: EdgeInsets.only(right: 30.w),
                    child:
                        _isNewPasswordVisible
                            ? Image.asset(
                              'assets/images/eye_open_icon.png',
                              width: 40.w,
                              height: 40.h,
                            )
                            : Image.asset(
                              'assets/images/eye_close_icon.png',
                              width: 40.w,
                              height: 40.h,
                            ),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(height: 41.h),
          // 确认密码输入框
          Container(
            width: 690.w,
            height: 110.h,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.r),
            ),
            child: Row(
              children: [
                SizedBox(width: 30.w),
                Text(
                  '确认密码',
                  style: TextStyle(
                    fontSize: 28.sp,
                    fontFamily: 'Source Han Sans',
                    color: const Color(0xFF333333),
                    height: 1.0,
                  ),
                ),
                SizedBox(width: 32.w),
                Expanded(
                  child: TextField(
                    controller: _confirmPasswordController,
                    obscureText: !_isConfirmPasswordVisible,
                    decoration: InputDecoration(
                      hintText: '请再次输入新密码',
                      hintStyle: TextStyle(
                        fontSize: 28.sp,
                        fontFamily: 'Source Han Sans CN',
                        color: const Color(0xFF999999),
                        height: 1.0,
                      ),
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.zero,
                    ),
                    style: TextStyle(
                      fontSize: 28.sp,
                      fontFamily: 'Source Han Sans CN',
                      color: const Color(0xFF333333),
                    ),
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    setState(() {
                      _isConfirmPasswordVisible = !_isConfirmPasswordVisible;
                    });
                  },
                  child: Padding(
                    padding: EdgeInsets.only(right: 30.w),
                    child:
                        _isConfirmPasswordVisible
                            ? Image.asset(
                              'assets/images/eye_open_icon.png',
                              width: 40.w,
                              height: 40.h,
                            )
                            : Image.asset(
                              'assets/images/eye_close_icon.png',
                              width: 40.w,
                              height: 40.h,
                            ),
                  ),
                ),
              ],
            ),
          ),
          const Spacer(),
          // 提交修改按钮
          GestureDetector(
            onTap: () {
              // 验证密码并提交修改逻辑
              if (_newPasswordController.text.isEmpty ||
                  _confirmPasswordController.text.isEmpty ||
                  _newPasswordController.text !=
                      _confirmPasswordController.text) {
                // 验证失败，不显示具体错误信息
                return;
              }
              // TODO: 实现密码修改逻辑
              // 成功后可以返回上一页或显示成功状态
              Get.back();
            },
            child: Container(
              width: 690.w,
              height: 88.h,
              margin: EdgeInsets.only(bottom: 100.h),
              decoration: BoxDecoration(
                color: const Color(0xFFDEEDFF),
                borderRadius: BorderRadius.circular(20.r),
                border: Border.all(color: const Color(0xFF79B4F9), width: 1.w),
              ),
              child: Center(
                child: Text(
                  '提交修改',
                  style: TextStyle(
                    fontSize: 28.sp,
                    fontFamily: 'Source Han Sans CN',
                    color: const Color(0xFF333333),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
